package com.ts.controller.achievement;

import com.ts.dto.TeachingResearchProjectDTO;
import com.ts.result.Result;
import com.ts.service.achievement.TeachingResearchProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 学术会议相关接口 - 学术会议相关成果的提交，查询
 */
@RestController
@RequestMapping("/achievement/teachingResearchProject")
@Tag(name = "教研项目相关接口", description = "教研项目的提交和查询功能")
@Slf4j
public class TeachingResearchProjectController {

    @Autowired
    private TeachingResearchProjectService teachingResearchProjectService;

    /**
     * 提交一个教研项目类型成果
     */
    @Operation(summary = "提交", description = "提交教研项目成果")
    @PostMapping()
    public Result saveTeachingResearchProject(@RequestBody TeachingResearchProjectDTO teachingResearchProjectDTO) {
        log.info("teachingResearchProjectDTO:{}", teachingResearchProjectDTO);
        teachingResearchProjectService.save(teachingResearchProjectDTO);
        return Result.success();
    }

    /**
     * 根据ID查询教研项目详情
     */
    @Operation(summary = "根据ID查询", description = "根据ID查询教研项目详情")
    @GetMapping("/{id}")
    public Result<TeachingResearchProjectDTO> getById(@PathVariable Long id) {
        log.info("查询教研项目ID: {}", id);
        TeachingResearchProjectDTO projectDTO = teachingResearchProjectService.getById(id);
        return Result.success(projectDTO);
    }

    /**
     * 更新教研项目
     */
    @Operation(summary = "更新", description = "更新教研项目")
    @PutMapping()
    public Result updateTeachingResearchProject(@RequestBody TeachingResearchProjectDTO teachingResearchProjectDTO) {
        log.info("更新教研项目: {}", teachingResearchProjectDTO);
        teachingResearchProjectService.update(teachingResearchProjectDTO);
        return Result.success();
    }

    /**
     * 根据ID删除教研项目
     */
    @Operation(summary = "删除", description = "根据ID删除教研项目")
    @DeleteMapping("/{id}")
    public Result deleteTeachingResearchProject(@PathVariable Long id) {
        log.info("删除教研项目ID: {}", id);
        teachingResearchProjectService.delete(id);
        return Result.success();
    }
}